#/bin/bash
#2017-12-12
Name=jdk-8u112-linux-x64.tar.gz
Url=http://mirror.xrk.org/jdk/linux/$Name 
Code=`curl -I -m 10 -o /dev/null -s -w %{http_code}  $Url`
if [ -e /usr/java/jdk1.8.0_112 ]; then
echo -e "\033[31m The JDK has been installed ...   \033[0m"
else 
echo -e "\033[32m  Ready to Install jdk1.8.0_112: \033[0m"
sleep 3
mkdir -p /usr/java && cd /usr/java

if [ $Code = "200" ]; then
wget $Url
else
wget http://mirror.cnop.net/jdk/linux/$Name 
fi
tar xf $Name
echo '
JAVA_HOME=/usr/java/jdk1.8.0_112
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
' >> /etc/profile
rm -rf  $Name
source /etc/profile
java -version 
echo "Jdk done."
fi